/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simple;

import chart.*;

import chart.RingChart;
import java.awt.Color;
import java.awt.event.ComponentEvent;
import java.util.Vector;

/**
 *
 * @author Jinhui
 */
public class PieChartPanel extends RingChart
{
  public PieChartPanel()
  {
    super();
  }
  @Override
  public void componentResized(ComponentEvent arg)
  {
    double RADIUS = Math.min(arg.getComponent().getWidth(), arg.getComponent().getHeight()) / 2;

    double radius = 0.1;
    double ringWidth = 0.0;
    Vector<Ring> rings = new Vector<Ring>();

    Ring ring1 = new Ring();
    // ring1.addItem("x", 0, Color.white);
    ringWidth = 0.05;
    radius += ringWidth;
    ring1.setRadius(radius * RADIUS);
    ring1.setRingWidth(ringWidth * RADIUS);
    rings.add(ring1);

    // evaluation ring
    ringWidth = 0.5;
    radius += ringWidth + 0.02;

    CompoundVerticalRing car = new CompoundVerticalRing();
    // evaluation category
    {
      VerticalRing ar = new VerticalRing();
      ar.addItem("Mac", 10, Color.blue);
      ar.addItem("Windows", 20, Color.red);
      ar.addItem("Linux", 30, Color.cyan);
      ar.addItem("other", 40, Color.green);
      ar.setRadius(radius * RADIUS);
      ar.setRingWidth(ringWidth * RADIUS);
      ar.setStart(0);
      ar.setEnd(10);
      car.AddVerticalRing(ar);
    }
    // evaluations
    {
      VerticalRing ar = new VerticalRing();
      for (int i = 0; i < 32; ++i)
      {
        if (i % 5 == 0 || i % 6 == 0)
        {
          ar.addItem("Mac", 10, Color.white);
        } else
        {
          ar.addItem("Mac", 10, new Color(145, 144, 139));
        }
      }
      ar.setRadius(radius * RADIUS);
      ar.setRingWidth(ringWidth * RADIUS);
      ar.setStart(10);
      ar.setEnd(120);
      car.AddVerticalRing(ar);
    }
    // evaluation category
    {
      VerticalRing ar = new VerticalRing();
      ar.addItem("Mac", 10, Color.red);
      ar.addItem("Windows", 20, Color.pink);
      ar.addItem("Linux", 30, Color.cyan);
      ar.setRadius(radius * RADIUS);
      ar.setRingWidth(ringWidth * RADIUS);
      ar.setStart(120);
      ar.setEnd(130);
      car.AddVerticalRing(ar);
    }
    // evaluations
    {
      VerticalRing ar = new VerticalRing();
      for (int i = 0; i < 21; ++i)
      {
        if (i == 0 || (i > 2 && i < 7))
        {
          ar.addItem("Mac", 10, Color.white);
        } else
        {
          ar.addItem("Mac", 10, Color.red);
        }
      }
      ar.setRadius(radius * RADIUS);
      ar.setRingWidth(ringWidth * RADIUS);
      ar.setStart(130);
      ar.setEnd(240);
      car.AddVerticalRing(ar);
    }
    // evaluation category
    {
      VerticalRing ar = new VerticalRing();
      ar.addItem("Mac", 10, Color.blue);
      ar.addItem("Windows", 20, Color.green);
      ar.addItem("Linux", 30, Color.cyan);
      ar.setRadius(radius * RADIUS);
      ar.setRingWidth(ringWidth * RADIUS);
      ar.setStart(240);
      ar.setEnd(250);
      car.AddVerticalRing(ar);
    }
    // evaluations
    {
      VerticalRing ar = new VerticalRing();
      ar.addItem("Mac", 10, Color.white);
      for (int i = 1; i < 21; ++i)
      {
        ar.addItem("Mac", 10, Color.blue);
      }
      ar.setRadius(radius * RADIUS);
      ar.setRingWidth(ringWidth * RADIUS);
      ar.setStart(250);
      ar.setEnd(360);
      car.AddVerticalRing(ar);
    }

    rings.add(car);


    //tags
    ringWidth = 0.15;
    radius += ringWidth + 0.02;
    {
      Ring ring = new Ring();
      for (int i = 0; i < 72; i++)
      {
        if (i % 6 == 0)
        {
          ring.addItem("Tag", 10, Color.black);
        } else
        {
          ring.addItem("Tag", 10, new Color(230, 230, 230));
        }
      }
      ring.setRingWidth(ringWidth * RADIUS);
      ring.setRadius(radius * RADIUS);
      rings.add(ring);
    }

    // tag classifications
    ringWidth = 0.05;
    radius += ringWidth;
    {
      Ring ring = new Ring();
      for (int i = 0; i < 24; i++)
      {
        ring.addItem("Tag", 10, new Color(i * 20 % 256, i * 10 % 256, i * 5));
      }
      ring.setRingWidth(ringWidth * RADIUS);
      ring.setRadius(radius * RADIUS);
      rings.add(ring);
    }


    // last ring - case study
    ringWidth = 1 - radius;
    radius = 1.0;
    // ring
    /*{
      Ring ring = new DistributedRing();
      for (int i = 0; i < 60; i++)
      {
        ring.addItem("Tag", 10, new Color(230, 230, 230));
      }

      ring.setRadius(radius * RADIUS);
      ring.setRingWidth(ringWidth * RADIUS);
      rings.add(ring);
    }*/
    {
      javax.persistence.EntityManager worldPUEntityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("worldPU").createEntityManager();
      javax.persistence.Query casestudyQuery = java.beans.Beans.isDesignTime() ? null : worldPUEntityManager.createQuery("SELECT c FROM Casestudy c");
      java.util.List<simple.Casestudy> casestudyList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : casestudyQuery.getResultList();

      Ring ring = new DistributedRing();
      for(int i = 0; i < casestudyList.size(); ++i)
      {
        simple.Casestudy cs = casestudyList.get(i);
        ring.addItem(cs.getName() + " " + cs.getCity() + " " + cs.getCountry(), radius, new Color(230, 230, 230));
      }

      ring.setRadius(radius * RADIUS);
      ring.setRingWidth(ringWidth * RADIUS);
      rings.add(ring);
    }

    setRings(rings);
    repaint();
  }
}
